package com.gx.ring.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.gx.ring.dao.RingBaseInterfaceDAO;
import com.gx.ring.entity.PersonalDownReport;

public class PDRInterfaceImplDAO implements RingBaseInterfaceDAO<PersonalDownReport> {
	private Connection conn = null;

	public PDRInterfaceImplDAO(Connection conn) {
		this.conn = conn;
	}

	@Override
	public List<PersonalDownReport> queryByphNumber(String phNumber) throws SQLException {
		String sql = "SELECT * FROM ring.t_personaldownreport WHERE PHONENUMBER=? ";
		List<PersonalDownReport> ls = new ArrayList<>();
		PersonalDownReport pdr = new PersonalDownReport();
		PreparedStatement pst = conn.prepareStatement(sql);
		pst.setString(1, phNumber);
		ResultSet rs = pst.executeQuery();
		if (rs.next()) {
			pdr = saveResult(rs);
			ls.add(pdr);
		}
		rs.close();
		pst.close();
		return ls;
	}



	@Override
	public PersonalDownReport saveResult(ResultSet rs) throws SQLException {
		PersonalDownReport pdr = new PersonalDownReport();
		pdr.setLogid(rs.getLong("LOGID"));
		pdr.setLogtime(rs.getTimestamp("LOGTIME"));
		pdr.setPhonenumber(rs.getString("PHONENUMBER"));
		pdr.setTtlid(rs.getLong("TTLID"));
		pdr.setPrice(rs.getLong("PRICE"));
		pdr.setResourcecode(rs.getString("RESOURCECODE"));
		pdr.setDowndate(rs.getTimestamp("DOWNDATE"));
		pdr.setSpcode(rs.getString("SPCODE"));
		pdr.setSpname(rs.getString("SPNAME"));
		pdr.setSendphonenumber(rs.getString("SENDPHONENUMBER"));
		pdr.setSendttlid(rs.getLong("SENDTTLID"));
		pdr.setDowntype(rs.getLong("DOWNTYPE"));
		pdr.setResourcetype(rs.getLong("RESOURCETYPE"));
		pdr.setResourcename(rs.getString("RESOURCENAME"));
		pdr.setUploadtype(rs.getLong("UPLOADTYPE"));
		pdr.setCorpdeptid(rs.getLong("CORPDEPTID"));
		pdr.setFeemark(rs.getLong("FEEMARK"));
		pdr.setFeetype(rs.getLong("FEETYPE"));
		pdr.setCansplit(rs.getLong("CANSPLITLONG"));
		pdr.setCanspdate(rs.getLong("CANSPDATE"));
		pdr.setRelativetime(rs.getLong("RELATIVETIME"));
		pdr.setExtendtime(rs.getLong("EXTENDTIME"));
		pdr.setOperatetype(rs.getLong("OPERATETYPE"));
		pdr.setUsertype(rs.getLong("USERTYPE"));
		pdr.setAdtype(rs.getLong("ADTYPE"));
		pdr.setAdmincode(rs.getString("ADMINCODE"));
		pdr.setOperator(rs.getLong("OPERATOR"));
		pdr.setDescription(rs.getString("DESCRIPTION"));
		pdr.setOperateid(rs.getLong("OPERATEID"));
		pdr.setModulecode(rs.getString("MODULECODE"));
		pdr.setPersontoneids(rs.getString("PERSONTONEIDS"));
		pdr.setCanuserupdate(rs.getLong("CANUSERUPDATE"));
		pdr.setUseintegral(rs.getLong("USEINTEGRAL"));
		pdr.setRingcardno(rs.getString("RINGCARDNO"));
		pdr.setAvailabledatetime(rs.getTimestamp("AVAILABLEDATETIME"));
		pdr.setPriceunit(rs.getLong("PRICEUNIT"));
		pdr.setProductid(rs.getString("PRODUCTID"));
		pdr.setValidday(rs.getTimestamp("VALIDDAY"));
		pdr.setResourceid(rs.getLong("RESOURCEID"));
		pdr.setUsdpip(rs.getString("USDPIP"));
		pdr.setRelativefreetime(rs.getLong("RELATIVEFREETIME"));
		pdr.setDownloadoperator(rs.getLong("DOWNLOADOPERATOR"));
		pdr.setDownloadmodulecode(rs.getString("DOWNLOADMODULECODESTRING"));
		return pdr;
	}

}
